#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <time.h>
#include "rngs.h"

int checkGainCard(int p, struct gameState *state) {

	srand(NULL);

	int r, handCount, deckCount, discardCount, supplyPos;

	handCount = state->handCount[p];
	deckCount = state->deckCount[p];
	discardCount = state->discardCount[p];
	supplyPos = rand() % 17;

	r = gainCard(supplyPos, state, 0, p);
	if (supplyCount(supplyPos, state) <= 0) {
		assert(r == -1);
		assert(discardCount == state->discardCount[p]);
	}
	else {
		assert(r == 0);
		assert(discardCount + 1 == state->discardCount[p]);
	}
	printf("tests passed!\n");

	supplyPos = rand() % 17;

	r = gainCard(supplyPos, state, 1, p);
	if (supplyCount(supplyPos, state) <= 0) {
		assert(r == -1);
		assert(deckCount == state->deckCount[p]);
	}
	else {
		assert(r == 0);
		assert(deckCount + 1 == state->deckCount[p]);
	}
	printf("tests passed!\n");

	supplyPos = rand() % 17;

	r = gainCard(supplyPos, state, 2, p);
	if (supplyCount(supplyPos, state) <= 0) {
		assert(r == -1);
		assert(handCount == state->handCount[p]);
	}
	else {
		assert(r == 0);
		assert(handCount + 1 == state->handCount[p]);
	}
	printf("tests passed!\n");
}

int main() {

	int r, p, discardCount, handCount, deckCount;
	int k[10] = {adventurer, council_room, feast, gardens, mine, remodel, smithy, village, baron, great_hall};

	struct gameState G;

	for (p = 0; p < 2; p++) {
		for (discardCount = 0; discardCount < 10; discardCount++) {
			for (handCount = 0; handCount < 10; handCount++) {
				for (deckCount = 0; deckCount < 10; deckCount++) {
					memset(&G, 23, sizeof(struct gameState));
					r = initializeGame(2, k, 1, &G);
					G.discardCount[p] = discardCount;
					memset(&G, 0, sizeof(int) * discardCount);
					G.handCount[p] = handCount;
					memset(&G, 0, sizeof(int) * handCount);
					G.deckCount[p] = deckCount;
					memset(&G, 0, sizeof(int) * deckCount);
					checkGainCard(p, &G);
				}
			}
		}
	}
}
